clear all;

load('comm_loc.mat','comm_loc');
load('input.mat','Z');
branch=comm_loc(:,1);
nmkt=length(branch);
p=unique(Z);
np=length(p);

result_num(1:np,1:2)=nan;
for i=1:np
    result_num(i,1)=sum(branch==1 & Z==p(i));
    result_num(i,2)=sum(branch==0 & Z==p(i));
end

result_num(:,1)=result_num(:,1)./sum(result_num(:,1));
result_num(:,2)=result_num(:,2)./sum(result_num(:,2));

fig=figure('Color',[1 1 1], 'Position',[200 200 800 320]);
axis square;
b=bar(result_num,'BarWidth',1);
b(1).FaceColor = 'blue';
b(2).FaceColor = 'red';
xticklabels({'$H_1$','$H_2$','$H_3$','$H_4$','$H_5$'})
set(gca,'TickLabelInterpreter','latex')
xlabel('market productivity', 'FontSize',12,'Interpreter','Latex');
ylabel('probability density', 'FontSize',12,'Interpreter','Latex');
set(gca,'FontSize',12);
legend('markets with branches in 1986','markets without branches in 1986','interpreter','latex')
ylim([0,0.35])
yticks(0:0.1:0.3)
